package utils.json.data;

import java.util.Iterator;

import utils.json.AbstractJSON;

import models.User;
import controllers.Security;

public class RoleJSON extends AbstractJSON {
	public RoleJSON() {
        for(String role : Security.ROLES) {
        	this.put(role, Boolean.FALSE);
        }
}

	public RoleJSON(User user) {
        this();
        this.checkUserRoles(user);
	}
	
	private void checkUserRoles(User user) {
        Iterator<String> rolesIt = this.keySet().iterator();
        while(rolesIt.hasNext()) {
                String role = rolesIt.next();
                if(user.getRoles() != null && user.getRoles().contains(role)) this.put(role, Boolean.TRUE);
        }
	}
}
